package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 林剑 on 2016/10/8.
 *
 * 惯性思维lte
 *
 *
 * 同46题一样，只需要删除多余的代码并且加上star即可
 *
 */
public class leetcode77 {

    public List<List<Integer>> combine(int n, int k) {
        ArrayList<List<Integer>> res = new ArrayList<List<Integer>>();
        ArrayList<Integer> item = new ArrayList<Integer>();

        if(n<=0)
            return res;
        permutation_helper(n,res,item,k,0);
        return res;
    }

    public void permutation_helper(int n, ArrayList<List<Integer>> res, ArrayList<Integer> item,int k,int start){
        if(item.size()==k){
            res.add(new ArrayList<Integer>(item));
            return;
        }

        for(int i = start; i<n;i++){
                item.add(i+1);
                permutation_helper(n,res,item,k,i+1);
                item.remove(item.size()-1);
        }
    }
    public static void main(String[] args) {
        leetcode77 leetcode77 = new leetcode77();
        System.out.println(leetcode77.combine(4,2));
    }
}
